#include "ring_buffer.h"

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <thread>
#include <chrono>


RingBuffer buffer;

void fun1()  //初始化构造函数
{
    std::cout << "Thread " << 1 << " executing" << std::endl;
    for(int i=0; i<10 ; i++)
    {
        std::string msg = buffer.get();
        std::cout << "get: " << msg << std::endl;
        while(msg.empty()){
            msg = buffer.get();
            std::this_thread::sleep_for(std::chrono::milliseconds(10));
        }
        std::cout << msg << std::endl;
    }
    //std::cout << "Thread " << n << " executing\n";
    //n += 10;
    std::this_thread::sleep_for(std::chrono::milliseconds(10));
    std::cout << "Thread " << 1 << " exit" << std::endl;
}

int main(int argc, char *argv[])
{
    std::vector<std::string> myVec;
    myVec.reserve(100);
    std::cout << "capacity:" << myVec.capacity() << std::endl;
    std::cout << "size:" << myVec.size() << std::endl;

    std::thread t1(fun1);

    for(int i=0; i<10 ; i++)
    {
        std::stringstream ss;
        ss << "hello " << i;
        buffer.put(ss.str());
        std::cout << "put: " << ss.str() << std::endl;
        std::this_thread::sleep_for(std::chrono::milliseconds(1000));
    }

    t1.join();

    return 0;
}

